$(function () {
    $.material.init();
    //切换左侧菜单
    var currentTime = 0;
    $('#toggleMenu,.body-cover').click(function () {
        $('.left-menu-box').toggleClass('active');
        $('.body-cover').toggle();
        if(new Date().getTime() - currentTime < 10000) return false;
        currentTime = new Date().getTime();
        //请求科室列表
        new followupPlan().getDeptList(function (res,status) {
            res = JSON.parse(res);
            if(res.code == '000'){
                var list = JSON.parse(res.data);
                var html = '';
                for(var i =0,len=list.length; i<len; i++){
                    html+=[
                        '<a href="./list.html?subdepttype='+ list[i].subdepttype +'">'+ list[i].subdepttypename +'</a>'
                    ].join('');
                }
                $('#deptFilterList').html(html);
            }
        });
        //请求医院列表
        new followupPlan().getHospList(function (res,status) {
            res = JSON.parse(res);
            if(res.code == '000'){
                var list = JSON.parse(res.data);
                var html = '';
                for(var i =0,len=list.length; i<len; i++){
                    html+=[
                        '<a href="./list.html?hospitalid='+ list[i].hospitalid +'">'+ list[i].hospitalname +'</a>'
                    ].join('');
                }
                $('#hospFilterList').html(html);
            }
        });
    });
    //注销
    $('a.logout').click(function () {
        localStorage.removeItem('token');
        localStorage.removeItem('sign');
        localStorage.removeItem('userInfo');
        localStorage.removeItem('previewFormJson');
        location.href= '../login/index.html';
    })
    //登录用户信息
    if(localStorage.userInfo){
        var infoJson = JSON.parse(localStorage.userInfo);
        var url = urlParam.basePictureUrl + infoJson.headphoto;
        if(!infoJson.headphoto){
            url = 'http://flup.leley.com/cholecystectomy/assets/avatars/avatar4.png';
            if(infoJson.sex == '女') url = 'http://flup.leley.com/cholecystectomy/assets/avatars/avatar3.png';
        }
        $('.user-info .face').attr('src',url);
        $('.user-info .name').text(infoJson.name);
        $('.user-info .job').text(infoJson.titlename);
        $('.user-info .address').text(infoJson.hospname +'  ' + infoJson.deptname);
    }
});